package controller;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

import controller.editor.EditorController;
import controller.editor.EntityCreationController;
import view.NewEntityView;

public class NewEntityController extends Controller{
	
	private EditorController controller;

	public NewEntityController(EditorController controller){
		this.controller = controller;
	}

	public void handleButtonEntidadGlobal(){
		NewEntityView.getInstance().hide();
		if (this.controller.getCurrentDiagram().getName().equals("Principal")){
			JDialog dialogo = new JDialog(); 
			JOptionPane.showMessageDialog(dialogo,"No se puede crear una entidad global en el diagrama Principal", "Notificacion",
					JOptionPane.INFORMATION_MESSAGE);	
		} else {
			SelectGlobalEntityController controller = new SelectGlobalEntityController(this.controller);
			controller.displayView();
		}
	}

	public void handleButtonEntidadNueva(){
		EntityCreationController c = new EntityCreationController(controller.getCurrentDiagram(), controller);
		c.displayView();
		NewEntityView.getInstance().hide();
	} 

	@Override
	public void displayView() {
		if (NewEntityView.getInstance().getController() == null){
			NewEntityView.getInstance().setController(this);
		}
		NewEntityView.getInstance().show();
	}
}
